package com.example.demo.test;

import com.example.demo.test.ruler.Ruler;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

@Data
@Slf4j
public abstract class AbstractWorkProcess extends Thread implements WorkProcess {

    private Ruler ruler;

    private boolean state = true;

    /**
     * 工序名称
     */
    private String processName;

    /**
     * 工序描述
     */
    private String description;

    /**
     * 参数
     */
    private Map<String,Object> parameters;

    /**
     * 物料
     */
    private Material material;

    public AbstractWorkProcess(String name, String description){
        this.processName = name;
        this.description = description;
    }

    /**
     * 得到当前要处理的物料
     */
    public abstract boolean getCurrentMaterial();

    @Override
    public abstract Material working();

    @Override
    public void run() {
        while (state){
            try {
                if(getCurrentMaterial()){
                    //TODO
                    log.info("工艺:"+processName+" 开始工作");
                    working();
                    log.info("工艺:"+processName+" 结束工作");
                    nextProcess();
                }
            }catch (Exception e){
                log.error("线程运行异常",e);
            }
        }
    }
}
